package com.nycreativity.elecreativity.generator

import com.baomidou.mybatisplus.annotation.IdType
import com.baomidou.mybatisplus.generator.AutoGenerator
import com.baomidou.mybatisplus.generator.config.DataSourceConfig
import com.baomidou.mybatisplus.generator.config.GlobalConfig
import com.baomidou.mybatisplus.generator.config.PackageConfig
import com.baomidou.mybatisplus.generator.config.StrategyConfig
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy


fun main() {

    // 代码生成器
    val mpg = AutoGenerator()

    //        全局配置
    val globalConfig = GlobalConfig()
    globalConfig.outputDir = System.getProperty("user.dir") + "/src/main/source"
    //        globalConfig.setOutputDir("C:\\Users\\sxt\\Desktop\\jd_proj");
    globalConfig.author = "sxt && ttxxi"
    globalConfig.isOpen = true
    globalConfig.idType = IdType.AUTO
    globalConfig.isKotlin = true
    globalConfig.serviceName = "%sService"
    mpg.globalConfig = globalConfig

    //        数据源配置
    val dataSourceConfig = DataSourceConfig()
    dataSourceConfig.url =
            "jdbc:mysql://182.254.227.223:3306/nongyuan?useUnicode=true&useSSL=false&characterEncoding=utf8&useTimezone=true&serverTimezone=GMT%2B8"
    dataSourceConfig.driverName = "com.mysql.cj.jdbc.Driver"
    dataSourceConfig.username = "nongyuan"
    dataSourceConfig.password = "123456"
    mpg.dataSource = dataSourceConfig

    // 包配置
    val pc = PackageConfig()
    //        pc.setModuleName("");
    pc.parent = "com.nycreativity.elecreativity"
    //        pc.setXml("mapper");
    mpg.packageInfo = pc

    // 策略配置
    val strategy = StrategyConfig()
    strategy.naming = NamingStrategy.underline_to_camel
    strategy.columnNaming = NamingStrategy.underline_to_camel
    strategy.isEntityLombokModel = true
    strategy.isRestControllerStyle = true
    //设置BaseEntity
    strategy.superEntityClass = "com.nycreativity.elecreativity.entity.BaseEntity";
    // 填写BaseEntity中的公共字段
    strategy.setSuperEntityColumns("creator", "create_time", "modifier", "modify_time", "is_del");
    strategy.logicDeleteFieldName = "is_del"


    // TODO: 2021/3/10 数据库表名的补充
//    strategy.setInclude("activity", "address", "brand", "favorite",
//            "goods", "goods_image", "goods_type", "order", "shopping_cart", "user","sku")
    strategy.setInclude("file")
    strategy.isControllerMappingHyphenStyle = true
    mpg.strategy = strategy
    mpg.execute()
}